<?php

class UserController extends Controller {

	private $DB;

	public function __Init(){
		$this->DB = new UserModel;
	}
	// 用户注册动作
	public function reg(){
		if(ISPOST && $_POST['account'] && $_POST['password']){
			if($this->DB->UserReg()){
				echo "<script>alert('注册成功');location.href='index.php';</script>";
				return true;
			}else{
				echo "<script>alert('".$this->DB->error."');location.href='index.php';</script>";
				return false;
			}
		}else{
			echo "<script>alert('请填写相关选项');location.href='index.php';</script>";
		}
	}
	// 登录动作
	public function login(){
		if(ISPOST && $_POST['account'] && $_POST['password']){
			if($this->DB->UserLogin()){
				echo "<script>alert('登录成功');location.href='index.php';</script>";
				return true;
			}else{
				echo "<script>alert('".$this->DB->error."');location.href='index.php';</script>";
				return false;
			}
		}else{
			echo "<script>alert('请填写用户名和密码');location.href='index.php';</script>";
		}
	}

	public function out(){
		session_unset();
		session_destroy();
		echo "<script>alert('已退出');location.href='index.php';</script>";
		return true;
	}




}

?>